<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="<?php echo __ACSS__;?>/font.css">
        <link rel="stylesheet" href="<?php echo __ACSS__;?>/xadmin.css">
        <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
        <script src="<?php echo __ALIB__;?>/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<?php echo __AJS__;?>/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
        <script src="<?php echo __AJS__;?>/html5.min.js"></script>
        <script src="<?php echo __AJS__;?>/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a>
              <cite>角色管理</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加角色','/index.php/admin/adminRole/roleAdd')"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form" id="project_table" lay-filter="project_table">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script src="<?php echo __AJS__;?>/jquery.min.js"></script>
    <script type="text/html" id="handle">
        <span class="layui-btn layui-btn-normal layui-btn-mini" lay-event="edit">编辑</span><span class="layui-btn layui-btn-danger layui-btn-mini" lay-event="delete">删除</span>
    </script>
    <script type="text/html" id="checkboxopen">
        <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_open" {{ d.status == 1 ? 'checked' : ''}}>
    </script>
    <script>
        $(function () {
            projectajax();
        });
        var labelsList;
        var formSelects1;
        function projectajax() {
            layui.use('table', function(){
                var table = layui.table;
                var form = layui.form;
                labelsList = table.render({
                    elem: '#project_table',
                    method:'post',
                    page:true,
                    page: {
                        layout: [ 'prev', 'page', 'next','count'],
                        limit:15
                    },
                    url: "/index.php/admin/adminRole/roleList",
                    cols:[[
                        {field: 'id',title: 'ID',align:'center'},
                        {field: 'title',title: '角色名',align:'center'},
                        {field: 'descr', title: '描述',align:'center'},
                        {field: 'status', title: '是否启用',templet: '#checkboxopen', unresize: true,align:'center'},
                        {title: '操作',toolbar:"#handle",align:'center'}
                    ]],
                    done: function(res, curr, count){
                        $(".layui-table-page").height(50);
                    }
                });

                //监听工具条
                table.on('tool(project_table)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'edit') {
                        xadmin.open('编辑角色',"/index.php/admin/adminRole/roleEdit?id="+data.id)
                    }else if (obj.event === 'delete') {
                        layer.confirm('确定删除吗？', {
                            btn: ['确定', '取消'],
                            btn1: function () {
                                $.post("/index.php/admin/adminRole/roleDel",{id:data.id}, function (res) {
                                    if (res.code==500){
                                        layer.alert(res.data, {
                                            icon: 5
                                        })
                                    }else{
                                        layer.msg(res.data,{icon:1,time:1000});
                                        // 对父窗口进行刷新
                                        window.setTimeout("xadmin.father_reload()",1000);
                                    }
                                },'json');
                            }
                        });
                    }
                });

                form.on('switch(is_open)', function(obj){
                    var status = 0;
                    if (obj.elem.checked){
                        status = 1;
                    }else{
                        status = 0;
                    }
                    $.ajax({
                        url: "/index.php/admin/adminRole/isOpen",
                        type: "post",
                        dataType:'json',
                        data:{id:this.value,status:status},
                        success: function (res) {
                            if(res.code == 200){
                                projectajax();
                                layer.msg(res.data,{icon:1,time:1000});
                            } else {
                                layer.msg(res.data,{icon:1,time:1000});
                            }
                        },
                        error:function (res) {
                            console.log('false='+res.data);
                        }
                    });
                });

            });
        }

      //预留批量删除
      function delAll (argument) {
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

</html>